import {ApiProperty} from "@nestjs/swagger";
import {Column} from "typeorm";

export class BaseEntity {
    @ApiProperty({description: "创建者ID"})
    @Column({name: "create_by", comment: "创建者ID", nullable: true})
    createBy: number;

    @ApiProperty({description: "创建时间"})
    @Column({name: "create_time", comment: "创建时间", nullable: true})
    createTime: Date;

    @ApiProperty({description: "修改人ID"})
    @Column({name: "update_by", comment: "修改人ID", nullable: true})
    updateBy: number;

    @ApiProperty({description: "修改时间"})
    @Column({name: "update_time", comment: "修改时间", nullable: true})
    updateTime: Date;


    constructor(createBy?: number, createTime?: Date, updateBy?: number, updateTime?: Date) {
        this.createBy = createBy;
        this.createTime = createTime;
        this.updateBy = updateBy;
        this.updateTime = updateTime;
    }

    public init(id: number): BaseEntity {
        this.createBy = id;
        this.createTime = new Date();
        this.updateBy = id;
        this.updateTime = new Date();
        return this;
    };

    public initCreate(id: number): BaseEntity {
        this.createBy = id;
        this.createTime = new Date();
        return this;
    }

    public initUpdate(id: number): BaseEntity {
        this.updateBy = id;
        this.updateTime = new Date();
        return this;
    }
}
